<?php

require_once ("Money.class.php");
require_once ("MoneyFactory.class.php");
require_once ("MoneyExceptions.php");

class PorteMonnaie {
    
    public static function add($m1,$m2) {
		
		$exc=new IncompatiblesCurrenciesException("incompatible currencies");
		
		if (!$m1->sameCurrency($m2)) {
			throw new IncompatiblesCurrenciesException();
		}
	        
	        $_factory=MoneyFactory::getDefaultFactory();
	    	
	    	return $_factory->createMoney($m1->getValue()+$m2->getValue(),$m1->getCurrency());	
    }


    public static function suppr($m1,$m2) {
		
		$exc=new IncompatiblesCurrenciesException("incompatible currencies");
		$excMoney=new NotEnoughMoneyException("Not Enough Money");
		
		if (!$m1->sameCurrency($m2)) {
			throw new IncompatiblesCurrenciesException();
		}
		
		if (!$m1->getValue()>$m2->getValue()) {
			throw new NotEnoughMoneyException();
		}

	        $_factory=MoneyFactory::getDefaultFactory();
	    	
	    	return $_factory->createMoney($m1->getValue()-$m2->getValue(),$m1->getCurrency());	
    }
}
?>
